<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/elementui/index.css">
    <script src="/js/vue/vue.js"></script>
    <script src="/js/axios/axios.min.js"></script>
    <script src="/js/qs/qs.min.js"></script>
    <script src="/js/elementui/index.js"></script>
</head>
<body>
<div id="app">

    <el-button type="danger"  icon="el-icon-plus" @click="dialogFormVisible = true">添加产线</el-button><br><br>

    <el-table
            :data="tableData"
            style="width: 100%">
        <el-table-column
                label="编号"
                >
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.id }}</span>
            </template>
        </el-table-column>
        <el-table-column
                label="名称"
        >
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.productionName }}</span>
            </template>
        </el-table-column>
        <el-table-column
                label="生产能力"
        >
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.productionCapacity }}组/天</span>
            </template>
        </el-table-column>
        <el-table-column
                label="负责人"
        >
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.principal }}</span>
            </template>
        </el-table-column>
        <el-table-column
                label="生产人数"
        >
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.num }}</span>
            </template>
        </el-table-column>
        <el-table-column
                label="生产状态"
        >
            <template slot-scope="scope">
                <span style="margin-left: 10px" v-if="scope.row.state == 0">正在生产</span>
                <span style="margin-left: 10px;color: red" v-if="scope.row.state == -1">未生产</span>
                <span style="margin-left: 10px;color: green" v-if="scope.row.state == 1">已生产</span>
            </template>
        </el-table-column>
        <el-table-column
                label="备注"
        >
            <template slot-scope="scope">
                <span style="margin-left: 10px">{{ scope.row.remark }}</span>
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="current"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>

    <!--显示-->

    <el-dialog title="设置生产记录" :visible.sync="dialogFormVisible" @close="closeMyDialog">
        <el-form :model="allProductionLine">
            <el-form-item label="名称" :label-width="formLabelWidth">
                <el-input v-model="allProductionLine.productionName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="生产能力" :label-width="formLabelWidth">
                <el-input v-model="allProductionLine.productionCapacity" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="负责人" :label-width="formLabelWidth">
                <el-input v-model="allProductionLine.principal" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="生产人数" :label-width="formLabelWidth">
                <el-input v-model="allProductionLine.num" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="生产状态" :label-width="formLabelWidth">
                <el-select v-model="allProductionLine.state" placeholder="请选择">
                    <el-option
                            v-for="item in productStatus2"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
                <!--<el-input v-model="allProductionLine.state" autocomplete="off"></el-input>-->
            </el-form-item>
            <el-form-item label="备注" :label-width="formLabelWidth">
                <el-input v-model="allProductionLine.remark" autocomplete="off"></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">关闭</el-button>
            <el-button type="primary" @click="saveProduct">确 定</el-button>
        </div>
    </el-dialog>
</div>
</body>
<script>
    new Vue( {
        el:"#app",
        data() {
            return {
                current:1,
                total:0,
                pageSize:5,
                tableData: [],
                dialogFormVisible:false,
                allProductionLine:{
                    id:"",
                    productionName:"",
                    productionCapacity:"",
                    principal:"",
                    num:"",
                    state:"",
                    remark:""
                },
                productStatus2:[
                    {label:"已生产",
                    value:"1"},
                    {label:"未生产",
                        value:"-1"},
                    {label:"正在生产",
                        value:"0"}
                ]
            }
        },
        methods: {
            handleEdit(index, row) {
                console.log(index, row);
                this.allProductionLine=row
                this.dialogFormVisible =true
            },
            handleDelete(index, row) {
                console.log(index, row);
                axios.delete("/allProductionLine?id="+row.id).then(value => {
                    if(value.data.code==1 && this.total-((this.curr-1)*this.pageSize)==1){
                        this.loadPage(this.current-1,this.pageSize);
                    }else {
                        this.loadPage(this.current,this.pageSize);
                    }
                })
            },
            handleSizeChange(pageSize) {
                //console.log(`每页 ${val} 条`);
                this.loadPage(this.current,pageSize)
            },
            handleCurrentChange(current) {
                //console.log(`当前页: ${val}`);
                this.loadPage(current,this.pageSize)
            },
            //关闭对话框
            closeMyDialog(){
                //清空数据
                this.allProductionLine = {      //产品对话框的数据
                    id:"",
                    productionName:"",
                    productionCapacity:"",
                    principal:"",
                    num:"",
                    state:"",
                    remark:""
                }
            },
            saveProduct(){
                if(this.allProductionLine.id==""){
                    axios.post("/allProductionLine",this.allProductionLine).then(value => {
                        if(value.data.code==1){
                            this.loadPage(this.current,this.pageSize)
                        }
                    })
                }else {
                    axios.put("/allProductionLine",this.allProductionLine).then(value => {
                        if(value.data.code==1){
                            this.loadPage(this.current,this.pageSize)
                        }
                    })
                }

                this.dialogFormVisible =false
            },
            loadPage(current,pageSize){
                this.current=current
                this.pageSize=pageSize
                axios.get("/allProductionLine?current="+current+"&pageSize="+pageSize).then(value => {
                    if(value.data.code==1){
                        this.tableData=value.data.data.records
                        this.total = value.data.data.total
                        this.pageSize = value.data.data.size
                        this.current = value.data.data.current
                    }
                })
            }
        },
        mounted(){
            this.loadPage(1,5)
        }
    })
</script>
</html>